package summer;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author JIANG ZHEN X6978
 * @since 2020年7月13日 下午3:38:15
 *
 *
 */
public class Client {

    public static void main(String[] args) throws Exception {

        String turnLine = "\n";
        final String client = "Client:";
        final String server = "Server:";

        int port = 4000;
        byte ipAddressTemp[] = { 127, 0, 0, 1 };
        InetAddress ipAddress = InetAddress.getByAddress(ipAddressTemp);

        Socket socket = new Socket(ipAddress, port);

        BufferedReader systemIn = new BufferedReader(new InputStreamReader(System.in));
        BufferedReader socketIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        PrintWriter socketOut = new PrintWriter(socket.getOutputStream());

        String readline = null;
        while (readline != "bye") {

            System.out.println(client);
            readline = systemIn.readLine();

            socketOut.println(readline);
            socketOut.flush();

            String inTemp = socketIn.readLine();

            System.out.println(server + turnLine + inTemp);
        }
        systemIn.close();
        socketIn.close();
        socketOut.close();
        socket.close();
    }
}
